'''
Created on May 24, 2011

@author: Roni
'''
import unittest
from cliques.cliqueFinder import cliqueFinder
from graph import graph
import logging
from graphUtils.scenarioGenerator import ScenarioGenerator

class Test(unittest.TestCase):


    def setUp(self):
        self.clique_finder = cliqueFinder()


    def tearDown(self):
        pass


    def testPrepareScenarios(self):
        nodes_range=[20,100,150]
        edge_factors=[12]
        k_range=xrange(3,6)
        iterations = 3
        generator = ScenarioGenerator("resources")
        generator.prepare_scenarios(nodes_range, edge_factors, k_range, iterations)

        for nodes in nodes_range:
            for edge_factor in edge_factors:
                for k in k_range:
                    for i in xrange(iterations):
                        a_scenario = generator.load(nodes,edge_factor,k,i)
                        self.clique_finder.setup(a_scenario.unknown_graph)

                        connected_comp = a_scenario.unknown_graph.connected_components()
                        comp_index = connected_comp[a_scenario.start_node]
                        comp_items = [item for item in connected_comp.keys() if connected_comp[item]==comp_index]
                        k_clique_exists = self.clique_finder.has_clique(k, comp_items)
                        self.assertTrue(k_clique_exists)
                        logging.info("Asserted %d,%d,%d,%d" % (nodes,edge_factor,k,i))

if __name__ == "__main__":
    #import sys;sys.argv = ['', 'Test.testName']
    logging.basicConfig(level=logging.INFO)
    unittest.main()